package com.roads.site.controller;

import com.roads.common.core.domain.AjaxResult;
import com.roads.site.constant.LabourConstant;
import com.roads.site.domain.chart.ChartModel;
import com.roads.site.service.IChartStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName SiteLabourChartController
 * @Description 图表controller
 * @Author nhp
 * @Date 2022/11/28 0010 11:14
 * @Version 1.0.0
 **/
@RestController
@RequestMapping("/labour/chart")
public class SiteLabourChartController {

    @Autowired
    private IChartStaffService chartStaffService;

    /**
     * 图表--劳务工状态饼状图
     *
     * @param institutionCode 标段编号
     * @return 结果
     */
    @GetMapping("/getStaffStatusChartPie")
    public AjaxResult getStaffStatusChartPie(String institutionCode) {
        AjaxResult ajaxResult = new AjaxResult();
        // 获取状态数据
        int pendingCount = chartStaffService.getStatusCount(institutionCode, LabourConstant.STAFF_STATUS_PENDING);
        int mobilizedCount = chartStaffService.getStatusCount(institutionCode, LabourConstant.STAFF_STATUS_MOBILIZED);
        int departureCount = chartStaffService.getStatusCount(institutionCode, LabourConstant.STAFF_STATUS_DEPARTURE);
        List<ChartModel> data = new ArrayList<>();
        ChartModel c1 = new ChartModel();
        c1.setValue(pendingCount);
        c1.setName("待进场");
        data.add(c1);
        ChartModel c2 = new ChartModel();
        c2.setValue(mobilizedCount);
        c2.setName("已进场");
        data.add(c2);
        ChartModel c3 = new ChartModel();
        c3.setValue(departureCount);
        c3.setName("已退场");
        data.add(c3);
        ajaxResult.put("data", data);
        return ajaxResult;
    }

    /**
     * 图表--劳务工分布图
     *
     * @param institutionCode 标段编号
     * @return 结果
     */
    @GetMapping("/getStaffProvinceChartMap")
    public AjaxResult getStaffProvinceChartMap(String institutionCode) {
        AjaxResult ajaxResult = new AjaxResult();
        List<ChartModel> data = chartStaffService.getStaffCountGroupProvince(institutionCode);
        ajaxResult.put("data", data);
        return ajaxResult;
    }

    /**
     * 图表--劳务工工种岗位柱状图-top10
     *
     * @param institutionCode 标段编号
     * @return 结果
     */
    @GetMapping("/getStaffPostChartBarTop10")
    public AjaxResult getStaffPostChartBarTop10(String institutionCode) {
        AjaxResult ajaxResult = new AjaxResult();
        List<ChartModel> data = chartStaffService.getStaffCountGroupPostTop10(institutionCode);
        ajaxResult.put("data", data);
        return ajaxResult;
    }

    /**
     * 图表--劳务工工种年龄柱状图
     *
     * @param institutionCode 标段编号
     * @return 结果
     */
    @GetMapping("/getStaffAgeChartBar")
    public AjaxResult getStaffAgeChartBar(String institutionCode) {
        AjaxResult ajaxResult = new AjaxResult();
        List<ChartModel> data = chartStaffService.getStaffCountGroupAge(institutionCode);
        ajaxResult.put("data", data);
        return ajaxResult;
    }

    /**
     * 图表--劳务工性别饼状图
     *
     * @param institutionCode 标段编号
     * @return 结果
     */
    @GetMapping("/getStaffSexChartPie")
    public AjaxResult getStaffSexChartPie(String institutionCode) {
        AjaxResult ajaxResult = new AjaxResult();
        // 获取状态数据
        int maleCount = chartStaffService.getSexCount(institutionCode, "1");
        int femaleCount = chartStaffService.getSexCount(institutionCode, "2");
        List<ChartModel> data = new ArrayList<>();
        ChartModel c1 = new ChartModel();
        c1.setValue(maleCount);
        c1.setName("男");
        data.add(c1);
        ChartModel c2 = new ChartModel();
        c2.setValue(femaleCount);
        c2.setName("女");
        data.add(c2);
        ajaxResult.put("data", data);
        return ajaxResult;
    }

}
